<?php
/**
 * Вернет дополнительную информацию о выпуске журнала используя поле issue_oid
 *
 * @package default
 * @author Alexander Sibiryakov
 **/
class AggregatedModel_ItemProcessor_IssueField extends AggregatedModel_ItemProcessor_Common implements AggregatedModel_ItemProcessor_Interface
{
	private $store;
	
	public function __construct($rh) {
		$this->store = $rh->ctx->store;
	}
	
	public function processItem(array $data) {
		$issue = NULL;

		// --- fetch linked issue --- {{{
		if ($data['issue_oid'] > 0) {
			$T = $this->store->db->db_prefix;
			$sql = "SELECT O.*, tdi.title AS tdi_title FROM {$T}objects O
					INNER JOIN t_acl_tree tat ON tat.id_object = O.oid AND tat.is_deleted = 0
					INNER JOIN {$T}class_issue iss ON iss.oid = O.oid 
					INNER JOIN {$T}class_tdi tdi ON tdi.oid = iss.tdi_oid
					WHERE O.oid = '{$data['issue_oid']}'
					";
			if ($rs_issue = $this->store->findSQL($sql)) {
				$issue = $rs_issue->next();
				$issue_row = $rs_issue->rs->current();
				$issue->data['tdi_title'] = $issue_row['tdi_title'];
			}
		}
		// --- fetch linked issue --- }}}
		
		if (isset($issue)) {
			$data['issue'] = $issue->data;
		} else {
			$data['issue'] = NULL;
		}
		
		return $data;
	}
} // END class 
